package mn.more.wits.client.dto;

/**
 * @author $Author: mikeliucc $
 * @version $Id: ExamQuestionDTO.java 5 2008-09-01 12:08:42Z mikeliucc $
 */
public class ExamQuestionDTO extends DataTransferObject {

	public static final int TYPE_MCQ = 0;
	public static final int TYPE_TF = 1;
	public static final int TYPE_ESSAY = 2;
	public static final int TYPE_FOLLOW_UP = 3;

	private ExamQuestionAttachmentDTO[] attachments;
	private String[] responses;

	protected void afterDeserialize() {
		String data = getData("responses");
		if (data != null) { responses = data.split(ARRAY_DELIM_STR); }

		data = getData("attachments");
		if (data != null) {
			String[] attachmentStrings = data.split(ARRAY_DELIM_STR);
			ExamQuestionAttachmentDTO[] attachments = new ExamQuestionAttachmentDTO[attachmentStrings.length];
			for (int i = 0; i < attachmentStrings.length; i++) {
				String attachmentString = attachmentStrings[i];
				attachments[i] =
					(ExamQuestionAttachmentDTO) toBaseModel(attachmentString, new ExamQuestionAttachmentDTO());
			}

			this.attachments = attachments;
		}
	}

	protected void beforeSerialize() {
		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < responses.length; i++) { buffer.append(responses[i]).append(ARRAY_DELIM); }
		setData("responses", buffer.toString());

		buffer = new StringBuffer();
		for (int i = 0; i < attachments.length; i++) {
			buffer.append(toModelString(attachments[i])).append(ARRAY_DELIM);
		}
		setData("attachments", buffer.toString());
	}

	//public String getQuestionId() { return getData("questionId"); }

	//public void setQuestionId(String questionId) {
	//	setData("questionId", questionId);
	//}

	public int getIndex() { return getIntData("index"); }

	public void setIndex(int index) { setData("index", index); }

	public int getType() { return getIntData("type"); }

	public void setType(int type) { setData("type", type); }

	public int getMcqMaxSelect() { return getIntData("mcqMaxSelect"); }

	public void setMcqMaxSelect(int mcqMaxSelect) { setData("mcqMaxSelect", mcqMaxSelect); }

	public String getText() { return getData("text"); }

	public void setText(String text) { setData("text", text); }

	public int getMaxMinute() { return getIntData("maxMinute"); }

	public void setMaxMinute(int maxMinute) { setData("maxMinute", maxMinute); }

	public boolean isLast() { return getBooleanData("isLast"); }

	public void setLast(boolean last) { setData("isLast", last); }

	public boolean isFirst() { return getIntData("index") == 1; }

	public ExamQuestionAttachmentDTO[] getAttachments() { return attachments; }

	public void setAttachments(ExamQuestionAttachmentDTO[] attachments) { this.attachments = attachments; }

	public String[] getResponses() { return responses; }

	public void setResponses(String[] responses) { this.responses = responses; }

}
